import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:hex/hex.dart';
import 'package:lib_util/utils/utils.dart';
import 'package:lib_web3/lib_solana_web3.dart';
import 'package:lib_web3/lib_tron_web3.dart';
import 'package:lib_web3/util/tronUtil.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // Map<String, dynamic> str = {
  //   "from": "0x52d90fb4022055731f6c11ac0686fab07f3c9b58",
  //   "to": "0x52d90fb4022055731f6c11ac0686fab07f3c9b58",
  //   //  value 是 wei  String?
  //   "value": '1',
  //   // gas 是 wei String?
  //   "gas": "21000",
  //   //  gasPrice 是 wei String?
  //   "gasPrice": "3000000000",
  // };
  // var data = await FlutterWeb3.getERC721OwnerTokenIds(
  //     rpcUrl: 'https://ethereum-goerli-rpc.publicnode.com',
  //     nftSeriesContract: '0x968eac12efa691295ab4ef566f2e585a068e73d1',
  //     userContract: '0x52D90fB4022055731F6C11Ac0686fAb07F3c9b58');
  // var data = await FlutterWeb3.getERC721NFTListInfo(
  //     rpcUrl: 'https://ethereum-goerli-rpc.publicnode.com',
  //     nftSeriesContract: '0x968eac12efa691295ab4ef566f2e585a068e73d1',
  //     userContract: '0x52D90fB4022055731F6C11Ac0686fAb07F3c9b58',
  //     userOwnerNftTokenIds:  ["28", "29", "61", "62", "63", "64", "65", "67", "68"]
  // );
  // int count = await ISOManager.loadBalanceFuture<int, String>(
  //     FlutterWeb3.getERC20BlockHeightByRpc, 'https://eth.llamarpc.com');
  // Map<String, dynamic>? data = await ISOManager.loadBalanceFuture<
  //     Map<String, dynamic>?,
  //     Map<String, String>>(FlutterWeb3.getERC20TokenInfoByRpc,{
  //   "rpcUrl": 'https://rpc.mevblocker.io',
  //   "tokenAddress": '0xdac17f958d2ee523a2206206994597c13d831ec7',
  // } );
  // var data = await TronWeb3.getBlockHeightByRpc('https://api.shasta.trongrid.io/jsonrpc');
  // var data2 = await SolanaWeb3.getBlockHeightByRpc('https://api.devnet.solana.com');
  // var data3 = await SolanaWeb3.getMainTokenBalance('https://api.devnet.solana.com','8rG9Q6eXun1sWMQsCRY5wbUrDoQfqVECkwkth3EdvfLC');
  // var getTokenBalance = await SolanaWeb3.getTokenBalance('https://api.devnet.solana.com',
  //     '0x67ef49a2240900405DDC8C0Fc7baAbb919ceBCD0','8rG9Q6eXun1sWMQsCRY5wbUrDoQfqVECkwkth3EdvfLC'
  //     );
  //  用户地址 A9jc2hMN9Xem6LVTxdD75Ub7Xx2NYS7QmgZ8JSPxHftg
  // 获取 solana 的 代币
  // var getTokenBalance = await SolanaWeb3.getTokenBalance('https://api.devnet.solana.com',
  //     '8rG9Q6eXun1sWMQsCRY5wbUrDoQfqVECkwkth3EdvfLC');
  // print('获取 solana 的    获取 solana 的 getTokenBalance：  $getTokenBalance');
  // 获取 solana 的 gas
  //主笔 接口获取 成功
  // var mainToken = await SolanaWeb3.getMainTokenBalance('https://api.devnet.solana.com','8rG9Q6eXun1sWMQsCRY5wbUrDoQfqVECkwkth3EdvfLC');
  // var getERC20TokenInfoByRpc = await SolanaWeb3.getERC20TokenInfoByRpc(
  //     'https://api.devnet.solana.com',
  //     '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU');
  // print('getERC20TokenInfoByRpc  $getERC20TokenInfoByRpc');
  // print('getTokenBalance $getTokenBalance');
  // print('data3 $data3');
  // print('data2 $data2');
  // print('data2 $data2');
  // var rpcUrl = 'https://nile.trongrid.io/jsonrpc';
  // var blockHeight = await TronWeb3.getBlockHeightByRpc(rpcUrl);
  // print('获取 波场 的 blockHeight $blockHeight');
  // var data = await TronWeb3.getMainTokenBalance(
  //     rpcUrl, 'TAKwucDj5wTFCPYL1XUGSNooPF63Etb1AV');
  // print('波场 的 主流币种余额 $data');
  //
  // var data2 = await TronWeb3.getTokenBalance(
  //     rpcUrl, 'TXLAQ63Xg1NAzckPwKHvzw7CSEmLMEqcdj','TAKwucDj5wTFCPYL1XUGSNooPF63Etb1AV');
  // print('波场 的 代币 余额 $data2');
  //
  // var data3 = await TronWeb3.getERC20TokenInfoByRpc(
  //     rpcUrl, tokenAddress: 'TF17BgPaZYbz8oxbjhriubPDsA7ArKoLX3',userAddress: 'TAKwucDj5wTFCPYL1XUGSNooPF63Etb1AV');
  // print('波场 的 代币 信息 $data3');
  //
  // var data4 = await TronWeb3.getErc20Gas(rpcUrl, {});
  // print('gas 的波场   $data4');



  //   ------------ solana ---------------
  var rpc ='https://api.devnet.solana.com';
  // var data = await SolanaWeb3.getBlockHeightByRpc(rpc);
  // print('solana 的区块高度   $data');
  // var data3 = await SolanaWeb3.getMainTokenBalance(rpc,'A9jc2hMN9Xem6LVTxdD75Ub7Xx2NYS7QmgZ8JSPxHftg');
  // print('solana 的主币   $data3');
  // var getTokenBalance = await SolanaWeb3.getTokenBalance(rpc,
  //     '9de6rLcqK4YNCNY7tiNVtZHfBDhbBK7pgZGcgwMvjWKb'
  //     );
  // print('solana 的代币   $getTokenBalance');
  // var gas = await SolanaWeb3.getErc20Gas(rpc,'');
  // print('solana 的gas 费用  $gas');
  final tran = {
    "from":"Esy1wQenXALQXCMjPVydeqyETRYDhKGntGzueAdMvqfu",
    "to":"Hsth4PpE8nsKkEG9q572kgztJMkULJRoRqg3s2TpoEwi",
    "value": '1',
  };
  var getERC20TokenInfoByRpc = await SolanaWeb3.getWeb3SignTx(
      rpc,
    11111,
      tran,
      'tokenAddress',
      'type'
      // accountAddress:'Hsth4PpE8nsKkEG9q572kgztJMkULJRoRqg3s2TpoEwi',
  );
  print('solana 的getERC20TokenInfoByRpc 费用  $getERC20TokenInfoByRpc');
}
